import {Component, OnInit} from '@angular/core';
import {HttpService} from '../../plugin/http/http.service';

@Component({
  selector: 'app-http',
  templateUrl: './http.component.html',
  styleUrls: ['./http.component.css']
})
export class HttpComponent implements OnInit {
  httpStatus;
  jsonData;

  constructor(private http: HttpService) {
  }

  ngOnInit() {
    /**
     * 请求接口后的处理
     */
    this.getTestJsonData().subscribe(res => {
      this.httpStatus = 'success';
      this.jsonData = res;
    }, err => {
      this.httpStatus = 'error';
      this.jsonData = err;
    });
  }

  /**
   * 发送请求的方法
   * @returns {Observable<ArrayBuffer> & Observable<ArrayBuffer>}
   */
  getTestJsonData() {
    return this.http.getData({
      url: '/portal/home/getUserInfo',
      search: {}
    });
  }
}
